﻿using System;

namespace IntoNails.Infrastructure.Activity
{
    public abstract class AbstractActivity : IActivity
    {
        public event EventHandler<ActivityCompletedEventArgs> Completed;

        protected virtual void RaiseCompleted()
        {
            this.RaiseCompleted(false);
        }

        protected virtual void RaiseCompleted(bool cancel)
        {
            var completed = this.Completed;
            if (completed != null)
            {
                completed(this, new ActivityCompletedEventArgs(cancel));
            }
        }

        protected virtual void RaiseCompleted(Exception error)
        {
            var completed = this.Completed;
            if (completed != null)
            {
                completed(this, new ActivityCompletedEventArgs(error));
            }
        }

        public abstract void Execute(ActivityContext context);
    }
}
